import request from './request'
import api,{apiPrefix} from './api'
const tApi:any=api;
const gen = (params:any,key:any) => {
  const prefix=apiPrefix as any;
  let url = prefix[key] + params
  let method = 'GET'

  const paramsArray = params.split(' ')
  if (paramsArray.length === 2) {
    method = paramsArray[0]
    url = prefix[key] + paramsArray[1]
  }

  return function(data:any) {
    return request({
      url,
      data,
      method,
    })
  }
}
const APIFunction:any = {}
for (const key in tApi) {
  for(const k in tApi[key])
    APIFunction[k] = gen(tApi[key][k],key)
}
// 自定义方法
// APIFunction.queryWeather = (params:any) => {
//   params.key = 'i7sau1babuzwhycn'
//   return request({
//     url: `${apiPrefix}/weather/now.json`,
//     data: params,
//   })
// }

export default APIFunction
